/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/*
 * DialogHariLiburDetail.java
 *
 * Created on 12 Feb 13, 18:53:25
 */
package sistemperpustakaan.view.harilibur;

import com.toedter.calendar.JDateChooser;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.util.Date;
import javax.swing.JTextField;
import sistemperpustakaan.controller.HariLiburController;
import sistemperpustakaan.model.HariLiburModel;
import sistemperpustakaan.utility.UserUtility;

/**
 *
 * @author EKo
 */
public class DialogHariLiburDetail extends javax.swing.JDialog {

    HariLiburController controller;
    HariLiburModel model = new HariLiburModel();
    boolean isNew;
    private String tanggal = "";

    /** Creates new form DialogHariLiburDetail */
    public DialogHariLiburDetail(java.awt.Frame parent, boolean modal, HariLiburController controller) {
        super(parent, modal);
        initComponents();
        this.controller = controller;
        this.controller.setHariLiburDetail(this);
        isNew = true;
        setTitle("Tambah Hari Libur");
//        setAction();
        setLocationRelativeTo(parent);
        Date date = new Date();
        txtTanggal.setDate(date);
        setButton();
        buttonSave.setEnabled(UserUtility.privilege[UserUtility.INSERT_UPDATE_DELETE]);
    }

    public DialogHariLiburDetail(java.awt.Frame parent, boolean modal, HariLiburController controller, String tanggal) {
        super(parent, modal);
        initComponents();
        this.controller = controller;
        this.controller.setHariLiburDetail(this);
        isNew = false;
        setTitle("Detail Hari Libur");
//        setAction();
        setLocationRelativeTo(controller.getHariLiburView());
        this.controller.showDetailHariLibur(tanggal);
        String tanggalLama=tanggal;
        setButton();
        buttonSave.setEnabled(UserUtility.privilege[UserUtility.INSERT_UPDATE_DELETE]);
    }

    public JTextField getTxtKeterangan() {
        return txtKeterangan;
    }

    public void setTxtKeterangan(JTextField txtKeterangan) {
        this.txtKeterangan = txtKeterangan;
    }

    public JDateChooser getTxtTanggal() {
        return txtTanggal;
    }

    public void setTxtTanggal(JDateChooser txtTanggal) {
        this.txtTanggal = txtTanggal;
    }

    public final void setButton() {
        buttonCancel.addActionListener(new ActionListener() {

            public void actionPerformed(ActionEvent e) {
                dispose();
            }
        });
        buttonSave.addActionListener(new ActionListener() {

            public void actionPerformed(ActionEvent e) {
                if (isNew) {
                    controller.saveNewHariLibur();
                } else {
                    controller.saveUpdateHariLibur();
                }
            }
        });
    }

    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        buttonSave = new javax.swing.JButton();
        buttonCancel = new javax.swing.JButton();
        jLabel11 = new javax.swing.JLabel();
        txtTanggal = new com.toedter.calendar.JDateChooser();
        jLabel12 = new javax.swing.JLabel();
        txtKeterangan = new javax.swing.JTextField();
        jLabel6 = new javax.swing.JLabel();
        gbr = new javax.swing.JLabel();

        setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);
        setResizable(false);
        getContentPane().setLayout(new org.netbeans.lib.awtextra.AbsoluteLayout());

        buttonSave.setText("Save");
        getContentPane().add(buttonSave, new org.netbeans.lib.awtextra.AbsoluteConstraints(200, 190, 82, -1));

        buttonCancel.setText("Cancel");
        getContentPane().add(buttonCancel, new org.netbeans.lib.awtextra.AbsoluteConstraints(288, 190, 82, -1));

        jLabel11.setHorizontalAlignment(javax.swing.SwingConstants.LEFT);
        jLabel11.setText("Tanggal Libur");
        jLabel11.setAlignmentY(1.0F);
        getContentPane().add(jLabel11, new org.netbeans.lib.awtextra.AbsoluteConstraints(10, 124, 120, -1));

        txtTanggal.setDateFormatString("dd MMMM yyyy");
        txtTanggal.setMinSelectableDate(new java.util.Date(-473407128000L));
        getContentPane().add(txtTanggal, new org.netbeans.lib.awtextra.AbsoluteConstraints(107, 124, 170, -1));

        jLabel12.setHorizontalAlignment(javax.swing.SwingConstants.LEFT);
        jLabel12.setText("Keterangan");
        jLabel12.setAlignmentY(1.0F);
        getContentPane().add(jLabel12, new org.netbeans.lib.awtextra.AbsoluteConstraints(10, 158, 109, -1));
        getContentPane().add(txtKeterangan, new org.netbeans.lib.awtextra.AbsoluteConstraints(107, 155, 260, -1));

        jLabel6.setFont(new java.awt.Font("Tahoma", 1, 14)); // NOI18N
        jLabel6.setText("Data Hari Libur Perpustakaan");
        getContentPane().add(jLabel6, new org.netbeans.lib.awtextra.AbsoluteConstraints(10, 10, -1, -1));

        gbr.setIcon(new javax.swing.ImageIcon(getClass().getResource("/sistemperpustakaan/image/calendar.png"))); // NOI18N
        getContentPane().add(gbr, new org.netbeans.lib.awtextra.AbsoluteConstraints(110, 10, 260, 200));

        pack();
    }// </editor-fold>//GEN-END:initComponents
    /**
     * @param args the command line arguments
     */
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton buttonCancel;
    private javax.swing.JButton buttonSave;
    private javax.swing.JLabel gbr;
    private javax.swing.JLabel jLabel11;
    private javax.swing.JLabel jLabel12;
    private javax.swing.JLabel jLabel6;
    private javax.swing.JTextField txtKeterangan;
    private com.toedter.calendar.JDateChooser txtTanggal;
    // End of variables declaration//GEN-END:variables
}
